 package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.crm.entity.MmrsT;
import cn.e4j.modular.crm.service.MmrsTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 配件库存维护 控制层
 * @author mengyb
 * @date 2019-04-10
 */
@Controller
@RequestMapping("/base/gwai680")
public class Gwai680Controller extends BaseController {

    @Autowired
    private MmrsTService mmrsTService;

    /**
     * 跳转至主界面
     *
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping(value = {"", "/init"})
    public String index() {
        return "/pc/crm/base/gwai680.html";
    }

    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getList")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrsTService.getList(inDto, page);

        return new PageReData(page, list);

    }
    /**
     * 产品开窗
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getGwamPageList")
    @ResponseBody
    public ResponseData getGwamPageList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrsTService.getGwamPageList(inDto,page);

        return new PageReData(page,list);

    }
    /**
     * 仓库库位开窗
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getGwatPageList")
    @ResponseBody
    public ResponseData getGwatPageList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = mmrsTService.getGwatPageList(inDto,page);

        return new PageReData(page,list);

    }

    /**
     * 获取产品数据列表
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getGwamList")
    @ResponseBody
    public Dto getGwamList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();

        List<Map<String, Object>> list = mmrsTService.getGwamList(inDto);

        Dto outDto = Dtos.newDto();

        outDto.put("list", list);

        return outDto;

    }

    /**
     * 获取仓库库位数据列表
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getGwatList")
    @ResponseBody
    public Dto getGwatList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();

        List<Map<String, Object>> list = mmrsTService.getGwatList(inDto);

        Dto outDto = Dtos.newDto();
        outDto.put("list", list);

        return outDto;

    }

    /**
     * 获取单位数据列表
     * @param dtoWapper
     * @return
     */
    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/getUnitList")
    @ResponseBody
    public Dto getUnitList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();

        List<Map<String, Object>> list = mmrsTService.getUnitList(inDto);

        Dto outDto = Dtos.newDto();
        outDto.put("list", list);

        return outDto;

    }


    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(MmrsT mmrsT) {
        if (mmrsTService.existedTheParams(mmrsT)) {
            return new ErrorResponseData(BizExceptionEnum.EXISTED_THE_PARAMS.getCode(),
                    BizExceptionEnum.EXISTED_THE_PARAMS.getMessage());
        } else {
            mmrsTService.add(mmrsT);
            return SUCCESS_TIP;
        }
    }

    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(MmrsT mmrsT) {
        mmrsTService.edit(mmrsT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/delRow")
    @ResponseBody
    public ResponseData delRow(MmrsT mmrsT) {
        mmrsTService.delRow(mmrsT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai680:init")
    @RequestMapping("/delRows")
    @ResponseBody
    public ResponseData delRows(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<MmrsT> mmrsTList = inDto.getReqList(MmrsT.class);
        mmrsTService.delRows(mmrsTList);
        return SUCCESS_TIP;
    }


}
